package com.gopay.bis.cmb.ebank.operation;

import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.cmb.ebank.query.CmbB2bQueryReq;
import com.gopay.common.domain.bank.cmb.ebank.query.CmbB2bQueryRes;
import com.gopay.common.domain.bank.cmb.ebank.query.Info;
import com.gopay.common.domain.bank.cmb.ebank.query.Sdktrdqyx;
import com.gopay.common.exception.GopayException;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class CmbB2bQueryHelper {

    private static String XML_HEAD="<?xml version=\"1.0\" encoding=\"GBK\"?>";
    
    /**
     * 拼装查询报文
     * @param msg  请求对象
     * @param loginName  登录用户名
     * @return 
     * @author w_jiqing
     */
    public String buildQueryXml (CmbB2bQueryReq message,String loginName){
        Info info =new Info();
            info.setFunnam("GetOrderStatus");
        info.setDattyp("2");
        info.setLgnnam(loginName);  
        Sdktrdqyx sdktrdqyx =new Sdktrdqyx();
        sdktrdqyx.setBegseq(message.getBankOrderId());
        message.setInfo(info);
        message.setSdktrdqyx(sdktrdqyx);
        XStream xstream = new XStream(new DomDriver("UTF-8", new NoNameCoder()));
        xstream.processAnnotations(message.getClass());
        return XML_HEAD+xstream.toXML(message);         
    }
    
    public CmbB2bQueryRes parseQueryXml(Object obj) throws GopayException{
        try{
            XStream xstream = new XStream(new DomDriver("UTF-8"));
            xstream.processAnnotations(CmbB2bQueryRes.class);
            return (CmbB2bQueryRes) xstream.fromXML((String) obj);
        } catch(Exception e){
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E6038);
        }
        
    }
}
